define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'games/game/index' + location.search,
                    add_url: 'games/game/add',
                    edit_url: 'games/game/edit',
                    // del_url: 'games/game/del',
                    multi_url: 'games/game/multi',
                    import_url: 'games/game/import',
                    table: 'game',
                }
            });

            var table = $("#table");
            Fast.config.openArea = ['60%','70%'];
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'game', title: __('Game'), operate: 'LIKE'},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'w_image', title: __('指定图片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'first', title: __('First'), operate: 'LIKE'},
                        {field: 'type', title: __("Type"), operate: 'LIKE',searchList: {"network":__('网游'),"mobile":__('手游')}, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'is_hot', title: __("Is_hot"), align: 'center',table: table,formatter: Table.api.formatter.toggle},
                        {field: 'status', title: __("状态"), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'cross',
                                    text: __(''),
                                    title: __('跨区'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-retweet',
                                    url: 'games/cross/index?ref=addtabs',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.id == 2){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    }
                                }
                            ]
                        }  
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
